<!DOCTYPE html>
<html lang="en" dir="ltr">
    <head>
        <meta charset="utf-8">
        <title>Nginx配置生成</title>
        <link rel="stylesheet" href="//mirror.fe80.cn/layui/2.6.8/css/layui.css">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <style>
            .layui-code {margin-top: 0;}
        </style>
    </head>
<body>
    <hr>
    <div class="layui-row">
        <div class="layui-col-md4">
            <form class="layui-form" action="#" onsubmit="return false">
                <div class="layui-form-item">
                    <label class="layui-form-label">域名</label>
                    <div class="layui-input-block">
                        <input type="text" name="domain" lay-verify="domain" autocomplete="off" placeholder="请输入域名" class="layui-input" value="i.fe80.cn">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">根目录</label>
                    <div class="layui-input-block">
                        <input type="text" name="rootpath" class="layui-input" id="rootpath" placeholder="请输入根目录" value="/home/www/market/public">
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">支持PHP</label>
                    <div class="layui-input-block">
                        <!-- <input type="text" name="rgb" lay-verify="rgb" autocomplete="off" placeholder="请输入RGB，空格分开" class="layui-input"> -->
                        <input type="checkbox" checked="" name="php" lay-skin="switch" lay-filter="php" lay-text="ON|OFF">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">配置缓存</label>
                    <div class="layui-input-block">
                        <!-- <input type="text" name="md5" lay-verify="md5" autocomplete="off" placeholder="请输入待加密的字符" class="layui-input"> -->
                        <input type="checkbox" checked="" name="cache" lay-skin="switch" lay-filter="cache" lay-text="ON|OFF">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">屏蔽UA</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="nua" lay-skin="switch" lay-filter="nua" lay-text="ON|OFF">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">404页面</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="n404" lay-skin="switch" lay-filter="n404" lay-text="ON|OFF">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">日志名称</label>
                    <div class="layui-input-block">
                        <!-- <textarea placeholder="请输入内容" name="base64" class="layui-textarea"></textarea> -->
                        <input type="text" name="logname" class="layui-input" id="logname" placeholder="请输入日志名称" value="i.fe80.cn">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="generate">立即提交</button>
                        <!-- <button class="layui-btn layui-btn-primary" lay-submit="" lay-filter="reset">清空</button> -->
                        <!-- <button type="reset" class="layui-btn layui-btn-primary">重置</button> -->
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-col-md8">
            <!-- <div class="grid-demo">50%</div> -->
            <div class="" id="result" style="padding:8px;padding-top: 0px;">
<pre class="layui-code" id="code">
server
{
    listen 80;
    listen [::]:80;
    server_name i.fe80.cn;
    index index.html index.htm index.php default.html default.htm default.php;
    root /home/www/market/public;
    if ($http_user_agent ~* (Scrapy|Curl|HttpClient|Hacker|Creaker|MSIE|Edge|Trident)) {
        rewrite  ^(.*)$  /deny  last;
    }
    include rewrite/thinkphp.conf;
    error_page   404   /404.html;
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }
    location ~ /.well-known {
        allow all;
    }
    location ~ /\.
    {
        deny all;
    }
    access_log  /home/wwwlogs/i.fe80.cn.log;
}
</pre>
            </div>
        </div>
    </div>
    <hr>
<script src="//mirror.fe80.cn/layui/2.6.8/layui.js" charset="utf-8"></script>
<script>
function getConf(info){
    var a1 = `server
{
    listen 80;
    listen [::]:80;
    server_name `;
    a1 += info.domain;
    a1 += `;
    index index.html index.htm index.php default.html default.htm default.php;
    root ` + info.rootpath + ';';
    if(info.nua=='on'){
        a1 += `
    if ($http_user_agent ~* (Scrapy|Curl|HttpClient|Hacker|Creaker|MSIE|Edge|Trident)) {
        rewrite  ^(.*)$  /deny  last;
    }`;
    }
    if (info.php == 'on') {
        a1 += `
    include rewrite/thinkphp.conf;`;
    }
    if (info.n404 == 'on') {
        a1 += `
    error_page   404   /404.html;`;
    }
    if(info.cache == 'on'){
        a1 += `
    location ~ .*\\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }
    location ~ .*\\.(js|css)?$
    {
        expires      12h;
    }
    location ~ /.well-known {
        allow all;
    }
    location ~ /\\.
    {
        deny all;
    }`;
    }
    if(info.logname){
        a1 += `
    access_log  /home/wwwlogs/`+ info.logname+`.log;`;
    }
    a1 += `
}`;
    return a1;
}
layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form,layer = layui.layer,$=layui.jquery,laydate = layui.laydate;

    //监听提交
    form.on('submit(generate)', function(data){
        var code = getConf(data.field);
        $('#code').text(code);
        return false;
    });

    //清空
    form.on('submit(reset)', function(data){
        console.log("清空");
        $("#result").find("blockquote").remove();
        return false;
    });
});
</script>
</body>
</html>
